package com.domain.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.domain.mapper.IUserMapper;
import com.domain.model.Sysuser;
import com.domain.util.ParseMD5;

@Service(value="userService") 
public class UserService {
	@Resource
	private IUserMapper userMapper;
	
	public void doAdd(Sysuser user) {
		user.setPassword(ParseMD5.parseStrToMd5L32(user.getPassword()));
		userMapper.doAdd(user);
	}

	/**
	 * 查询全部用户列表
	 * @return 用户列表
	 */
	public List<Sysuser> doUserList(){
		List<Sysuser> users = userMapper.doUserList();
		return users;
	}
	
	/**
	 * 根据编号查询单个用户
	 * @param id
	 * @return
	 */
	public Sysuser getUserById(Long id){
		
		Sysuser user = userMapper.getUserById(id);
		return user;
	}
	
	/**
	 * 修改单个用户信息
	 * @param role
	 */
	public void editUser(Sysuser user){
		user.setPassword(ParseMD5.parseStrToMd5L32(user.getPassword()));
		userMapper.editUser(user);
	}
	
	/**
	 * 根据用户名和密码获取单个用户信息
	 */
	public Sysuser getUserByUserNameAndPsw(Sysuser user){
		return userMapper.getUserByUserNameAndPsw(user);
		
	}
	 /**
	  * 根据用户名获取用户对象，如果有多个，返回最新的哪一个
	  *  TODO(方法的作用)
	  * @author liujie
	  * @date 2015年4月24日 下午4:25:32
	  * @param user
	  * @return
	  */
	 public Sysuser	getUserByUserName(Sysuser user){
		 return userMapper.getUserByUserName(user);
	 }
	
	/**
	 * 删除单个用户
	 */
	public void doDelUser(Long id){
		userMapper.doDelUser(id);
	}
}
